<?php

namespace App\Admin\Controllers;

use App\Admin\Grid\NGrid;
use App\Admin\Service\NotifyService;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid\Displayers\Actions;
use Encore\Admin\Show;

class NotifyController extends AdminController
{
    private NotifyService $service;

    /**
     * @param NotifyService $service
     */
    public function __construct(NotifyService $service)
    {
        $this->service = $service;
    }

    /**
     * grid
     * @return NGrid
     */
    protected function grid(): NGrid
    {
        $this->service->grid();
        $this->service->using('type');
        $this->service->column('created_at');
        $this->service->grid->disableActions(false);
        $this->service->grid->actions(function (Actions $action) {
            $action->disableDelete();
            $action->disableView(false);
            $action->disableEdit();
        });
        return $this->service->grid;
    }

    /**
     * detail
     * @param int $id
     * @return Show
     */
    protected function detail(int $id): Show
    {
        $this->service->show($id);
        $this->service->using('type');
        $this->service->show->field('result', $this->service->ml['result'])->json();
        $this->service->field('createdAt');
        return $this->service->show;
    }
}
